package com.besovideo.mpu;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.smarteye.mpu.MPUGlobal;
import com.smarteye.mpu.MainService.Connection;


public class TransactionDialog extends Dialog {
	
	Context context;
	int lay;
	private Connection mConnection;
	RadioGroup m_RadioGroup;
	private RadioButton m_TransactionOpen;
	private RadioButton m_TransactionClose;
	private RadioButton m_TransactionAuto;
	
	public TransactionDialog(Context context) {
		super(context, R.style.TransparentDialogHaveTitle);
		this.context = context;
		this.lay = R.layout.transaction_set_dialog;
		mConnection = ((MPUGlobal) ((MainActivity) context).getApplication()).getConnection();
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(lay);
		m_TransactionOpen = (RadioButton)findViewById(R.id.radioButtonTransactionOpen);
		m_TransactionClose = (RadioButton)findViewById(R.id.radioButtonTransactionClose);
		m_TransactionAuto = (RadioButton)findViewById(R.id.radioButtonTransactionAuto);

		m_RadioGroup = (RadioGroup)findViewById(R.id.radioGroupTransaction);
		m_RadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup arg0, int checkedId) {
				// TODO Auto-generated method stub
				MainActivity parent = (MainActivity)context;
				if (checkedId == m_TransactionOpen.getId()) {
					parent.mainConfigMenuListViewAdapter.setText(
							MainActivity.MainConfigMenuEnum.MAIN_MENU_TRANSACTION.value(),
							m_TransactionOpen.getText().toString());
				} else if (checkedId == m_TransactionClose.getId()) {
					parent.mainConfigMenuListViewAdapter.setText(
							MainActivity.MainConfigMenuEnum.MAIN_MENU_TRANSACTION.value(), 
							m_TransactionClose.getText().toString());
				} else if (checkedId == m_TransactionAuto.getId()) {
					parent.mainConfigMenuListViewAdapter.setText(
							MainActivity.MainConfigMenuEnum.MAIN_MENU_TRANSACTION.value(),
							m_TransactionAuto.getText().toString());
				}
				parent.mainConfigMenuListViewAdapter.notifyDataSetChanged();
				dismiss();
			}
		});
	}
}